﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using ECare.BUS;
using ECare.BUS.Data;
using ECare.Client.templates;

namespace ECare.Client.frms
{
    public partial class frmPlanUnFinished : frmNull
    {
        public frmPlanUnFinished()
        {
            InitializeComponent();

            this.Load += frmPlanUnFinished_Load;

            
        }

        void frmPlanUnFinished_Load(object sender, EventArgs e)
        {
            //throw new NotImplementedException();
            this.tileControl1.Groups.Clear();
            this.LoadPlans();
        }

        private void LoadPlans()
        {
            var source = PlanHelper.GetPlans("1=1 ", true);
            var newgroup = new TileGroup();
            this.tileControl1.Groups.Add(newgroup);
            foreach (var plan in source)
            {
                var newitem = new TileItem
                {
                    ItemSize = TileItemSize.Wide,
                    Text = FormulaHelper.GetFormulaInfoById(plan.formula_id),
                    Tag = plan
                };

                var info=  new DevExpress.XtraEditors.TileItemElement();
                //
                var detailes = PlanHelper.GetPlanDetails(plan);

                info.Text = string.Format("总计 {0}, 未完成 {1}", plan.plan_times,
                    detailes.Count(a => a.plan_detail_status == PlanStatus.pending));

                newitem.Elements.Add(info);


                var infodate = new DevExpress.XtraEditors.TileItemElement();
                infodate.Text = plan.plan_date.ToShortDateString();

                newitem.Elements.Add(infodate);
               
                newitem.AppearanceItem.Normal.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(0)))), ((int)(((byte)(114)))), ((int)(((byte)(198)))));


                newitem.ItemClick += newitem_ItemClick;

                newgroup.Items.Add(newitem);
            }


        }

        void newitem_ItemClick(object sender, TileItemEventArgs e)
        {
            //throw new NotImplementedException();
            var currentplan = e.Item.Tag as PlanInfo;
            var frmwizard = new frmWizard();
            frmwizard.currentPlan = currentplan;
            frmwizard.ShowDialog();

        }
    }
}
